package com.example.api.controller;

import com.example.api.aspect.SystemControllerLog;
import com.example.api.model.entity.Toll;
import com.example.api.model.enums.ActionTypeEnum;
import com.example.api.model.support.RespBean;
import com.example.api.service.TollService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "收费管理")
@RestController
@RequestMapping("/api/toll")
public class TollController {

    @Resource
    private TollService tollService;

    @ApiOperation("查询收费列表")
    @GetMapping("/")
    @SystemControllerLog(description = "查询收费列表", actionType = ActionTypeEnum.QUERY)
    public List<Toll> findAll(String name) {
        return tollService.findAll(name);
    }

    @ApiOperation("更新收费信息")
    @PutMapping("/")
    @SystemControllerLog(description = "更新收费信息", actionType = ActionTypeEnum.UPDATE)
    public RespBean update(@RequestBody Toll toll) {
        return tollService.update(toll);
    }

    @ApiOperation("收费详情")
    @GetMapping("/{id}")
    @SystemControllerLog(description = "收费详情", actionType = ActionTypeEnum.QUERY)
    public Toll findById(@PathVariable Integer id) {
        return tollService.findById(id);
    }

}
